<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>

<%@ page import="com.conversationboard.config.*" %>
<%@ page import="com.conversationboard.model.StyleSheets"%>

<%@ page pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8"%>

<%@ page import="com.conversationboard.view.MainMenu"%>
<%@ page import="com.conversationboard.controller.confirm.Confirm"%>
<%@ page import="java.util.Map"%>
<%@ page import="com.conversationboard.model.preferences.SiteNewPostsViewInfo"%>
<%@ page import="com.conversationboard.site.Site"%>

<%
	if (request.getParameter("selectAll") != null) {
		request.setAttribute("checked", "CHECKED");
	} else {
		request.setAttribute("checked", "");
	}

	Map<Integer, SiteNewPostsViewInfo> viewInfo = (Map<Integer, SiteNewPostsViewInfo>) request.getAttribute("viewInfo");

	String key = Confirm.getKey(request.getUserPrincipal().getName());
	
%>

<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<title>Customise Site View</title>
		<link rel="stylesheet"title="Conversation Board" type="text/css" href="<%=Configuration.getInstance().getRoot()%>/Stylesheets/<%=StyleSheets.getStyleSheetFileName(request.getCookies())%>">
	</head>

	<body>

		<%= MainMenu.display(request.getUserPrincipal()) %>
	
		<div class="headingblock">
			<h1>Customise Site View</h1>
		</div>

		<div class="mainblock">
			<div class="formsectionlight">
			
				<h2>Message Boards</h2>

				<p>From here, you can select the board whose threads will be shown on the "Site New <%= Site.getPost()%>s" and "Site New <%= Site.getThread()%>s" pages.
				   You can also select a colour the board will be identified with when you are logged into the site.</p> 

				<form action="<%=Configuration.getInstance().getRoot()%>/UpdateSiteNewPostsPreferencesControllerServlet" method="post">
					<%= key %>					
				 	<input type="hidden" name="restoreDefaults" value="true" />
				 	<input type="submit" value="   Restore Defaults   " />
				</form>


				<form name="customiseForm" class="formsection" action="<%=Configuration.getInstance().getRoot()%>/UpdateSiteNewPostsPreferencesControllerServlet" method="post">

					<%= key %>					
	
					<table class="table">
						
						<tr class="header">
							<td class="cell">Board Name</td>
							<td class="cell">Show? (<a href="<%= Configuration.getInstance().getRoot() %>/CustomiseSiteNewPostsControllerServlet?selectAll=true">All</a>/<a href="<%= Configuration.getInstance().getRoot() %>/CustomiseSiteNewPostsControllerServlet?selectNone=true">None</a>)</td>
							<td class="cell">Colour</td>
						</tr>			
					
						<c:forEach var="board" items="${boards}">
							<tr class="row">
								<td class="cell">${board.name}</td>
								
								<c:choose>
									<c:when test="${not viewInfo[board.boardId].hide and not param.selectNone}">
										<td class="cell"><input type="checkbox" name="hide${board.boardId}" value="true" CHECKED /></td>
									</c:when>

									<c:otherwise>
										<td class="cell"><input type="checkbox" name="hide${board.boardId}" value="true" ${checked} /></td>
									</c:otherwise>								
								</c:choose>
								
								<td class="cell">
									<select name="colour${board.boardId}">
									
										<c:forEach var="colour" items="${colours}">
										
											<c:choose>
												<c:when test="${viewInfo[board.boardId] ne null and viewInfo[board.boardId].colour eq colour.htmlCode}">
													<c:set var="selected">selected</c:set>
												</c:when>
											
												<c:otherwise>
													<c:set var="selected"></c:set>
												</c:otherwise>
											</c:choose>
										
											<option ${selected} value="${colour.htmlCode}">${colour.displayName}
										</c:forEach>
										
									</select>
								</td>
							</tr>
						</c:forEach>
					</table>
	
					<br />
				 	<input type="submit" value="   Update My Preferences   " />
				</form>

			</div>
		</div>
			
		<!--<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>-->
		<!--<script type="text/javascript">_uacct = "UA-1148679-1";urchinTracker();</script>--> 
		
	</body>
	
</html>
